package com.yuntu.service;

import com.yuntu.dao.PageUtil;
import com.yuntu.dao.PeitemsMapper;
import com.yuntu.pojo.Peitems;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PeitemsServiceImpl implements PeitemsService{
    @Autowired
    private PeitemsMapper peitemsMapper;
    @Override
    public void getPageAll(PageUtil<Peitems> pageUtil) throws Exception {
        List<Peitems> peitemsList = new ArrayList<>();
        int count = peitemsMapper.getCount();
        pageUtil.setCounts(count);
        if (count>0){
            if (pageUtil.getPageindex()>pageUtil.getPagecount()){
                pageUtil.setPageindex(pageUtil.getPagecount());
            }
            peitemsList=peitemsMapper.getPageAll(pageUtil);
            pageUtil.setLists(peitemsList);
        }
    }

    @Override
    public Peitems getAllById(int itemid) throws Exception {
        return peitemsMapper.getAllById(itemid);
    }

    @Override
    public boolean insert(Peitems peitems) throws Exception {
        boolean flag = false;
        if (peitemsMapper.insert(peitems)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean peitemsUpd(Peitems peitems) throws Exception {
        boolean flag = false;
        if (peitemsMapper.peitemsUpd(peitems)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean deleteById(int itemid) throws Exception {
        boolean flag = false;
        if (peitemsMapper.deleteById(itemid)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Peitems selectNotRepeat(String itemname)throws Exception {
        return peitemsMapper.selectNotRepeat(itemname);
    }
}
